package wyp.library.tools;

import java.security.MessageDigest;

import Decoder.BASE64Decoder;
import Decoder.BASE64Encoder;
/**
 * 需sun.misc.BASE64Decoder.jar
 * @author Administrator
 *
 */
public class Base64Util {

	
	  private static final String KEY_MD5 = "MD5";


	/**
     * BASE64解密
     * @param key
     * @return
     * @throws Exception
     */
    public static byte[] decryptBASE64(String key) throws Exception{
        return (new BASE64Decoder()).decodeBuffer(key);
    }
    
     /**
     * BASE64加密
     * @param key
     * @return
     * @throws Exception
     */
    public static String encryptBASE64(byte[] key)throws Exception{
        return (new BASE64Encoder()).encodeBuffer(key);
    }
    
    
    /**
     * MD5加密
     * @param data
     * @return
     * @throws Exception
     */
    public static byte[] encryptMD5(byte[] data)throws Exception{	       
    	MessageDigest md5 = MessageDigest.getInstance(KEY_MD5);
        md5.update(data);
        return md5.digest();
    }
}
